# encoding = utf-8
class CommentsController < ApplicationController
  
  before_filter :authenticate_user!, :only => [:new, :create]
  
  def new
    @comment = Comment.new
    @parent = params[:format]+'_id'
    @pid = params[:id]
    
    render :layout => false
  end
  
  def create
    params[:comment][:user_id] = current_user.id
    @comment = comment.new(params[:comment])

    if @comment.save
      flash[:success] = '评论发表成功'
    else
      flash[:error] = @comment.errors
    end

    redirect_to '/home'
  end
  
end
